package com.ddxz.tool.http.factory;

import com.ddxz.tool.http.DdxzHttpClient;
import com.ddxz.tool.http.method.DdxzHttpDelete;
import com.ddxz.tool.http.method.DdxzHttpGet;
import com.ddxz.tool.http.method.DdxzHttpPost;
import com.ddxz.tool.http.method.DdxzHttpPut;

/**
 * class description
 *
 * @author 朱宗刚
 * @version 1.0.0
 * @date 2020/11/30
 */

public class RequestFactory extends DdxzHttpClient {
    public static AbstractDdxzHttpRequest getHttpRequest(DdxzHttpMethod method) {
        switch (method) {
            case GET:
                return new DdxzHttpGet(DdxzHttpClient.getHttpClient());
            case PUT:
                return new DdxzHttpPut(DdxzHttpClient.getHttpClient());
            case POST:
                return new DdxzHttpPost(DdxzHttpClient.getHttpClient());
            case DELETE:
                return new DdxzHttpDelete(DdxzHttpClient.getHttpClient());
            default:
                return null;
        }
    }

    public static AbstractDdxzHttpRequest getHttpsRequest(DdxzHttpMethod method) {
        switch (method) {
            case GET:
                return new DdxzHttpGet(DdxzHttpClient.getHttpsClient());
            case PUT:
                return new DdxzHttpPut(DdxzHttpClient.getHttpsClient());
            case POST:
                return new DdxzHttpPost(DdxzHttpClient.getHttpsClient());
            case DELETE:
                return new DdxzHttpDelete(DdxzHttpClient.getHttpsClient());
            default:
                return null;
        }
    }

    public static AbstractDdxzHttpRequest getHttpRequest(DdxzHttpMethod method, long timeout) {
        switch (method) {
            case GET:
                return new DdxzHttpGet(DdxzHttpClient.getHttpClient(timeout));
            case PUT:
                return new DdxzHttpPut(DdxzHttpClient.getHttpClient(timeout));
            case POST:
                return new DdxzHttpPost(DdxzHttpClient.getHttpClient(timeout));
            case DELETE:
                return new DdxzHttpDelete(DdxzHttpClient.getHttpClient(timeout));
            default:
                return null;
        }
    }

    public static AbstractDdxzHttpRequest getHttpsRequest(DdxzHttpMethod method, long timeout) {
        switch (method) {
            case GET:
                return new DdxzHttpGet(DdxzHttpClient.getHttpsClient(timeout));
            case PUT:
                return new DdxzHttpPut(DdxzHttpClient.getHttpsClient(timeout));
            case POST:
                return new DdxzHttpPost(DdxzHttpClient.getHttpsClient(timeout));
            case DELETE:
                return new DdxzHttpDelete(DdxzHttpClient.getHttpsClient(timeout));
            default:
                return null;
        }
    }

    public static AbstractDdxzHttpRequest getHttpsRequest(DdxzHttpMethod method, int maxPoolSize) {
        switch (method) {
            case GET:
                return new DdxzHttpGet(DdxzHttpClient.getHttpsClient(maxPoolSize));
            case PUT:
                return new DdxzHttpPut(DdxzHttpClient.getHttpsClient(maxPoolSize));
            case POST:
                return new DdxzHttpPost(DdxzHttpClient.getHttpsClient(maxPoolSize));
            case DELETE:
                return new DdxzHttpDelete(DdxzHttpClient.getHttpsClient(maxPoolSize));
            default:
                return null;
        }
    }

    public static AbstractDdxzHttpRequest getHttpRequest(DdxzHttpMethod method, int maxPoolSize) {
        switch (method) {
            case GET:
                return new DdxzHttpGet(DdxzHttpClient.getHttpClient(maxPoolSize));
            case PUT:
                return new DdxzHttpPut(DdxzHttpClient.getHttpClient(maxPoolSize));
            case POST:
                return new DdxzHttpPost(DdxzHttpClient.getHttpClient(maxPoolSize));
            case DELETE:
                return new DdxzHttpDelete(DdxzHttpClient.getHttpClient(maxPoolSize));
            default:
                return null;
        }
    }

    public static AbstractDdxzHttpRequest getHttpRequest(DdxzHttpMethod method, int maxPoolSize, long timeout) {
        switch (method) {
            case GET:
                return new DdxzHttpGet(DdxzHttpClient.getHttpClient(maxPoolSize, timeout));
            case PUT:
                return new DdxzHttpPut(DdxzHttpClient.getHttpClient(maxPoolSize, timeout));
            case POST:
                return new DdxzHttpPost(DdxzHttpClient.getHttpClient(maxPoolSize, timeout));
            case DELETE:
                return new DdxzHttpDelete(DdxzHttpClient.getHttpClient(maxPoolSize, timeout));
            default:
                return null;
        }
    }

    public static AbstractDdxzHttpRequest getHttpsRequest(DdxzHttpMethod method, int maxPoolSize, long timeout) {
        switch (method) {
            case GET:
                return new DdxzHttpGet(DdxzHttpClient.getHttpsClient(timeout, maxPoolSize));
            case PUT:
                return new DdxzHttpPut(DdxzHttpClient.getHttpsClient(timeout, maxPoolSize));
            case POST:
                return new DdxzHttpPost(DdxzHttpClient.getHttpsClient(timeout, maxPoolSize));
            case DELETE:
                return new DdxzHttpDelete(DdxzHttpClient.getHttpsClient(timeout, maxPoolSize));
            default:
                return null;
        }
    }

    public enum DdxzHttpMethod{
        /**
         * HTTP的请求类别
         */
        GET,PUT,POST,DELETE
    }
}
